package pl.edu.mimuw.irs.rcp.controller.part;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;

import pl.edu.mimuw.irs.core.model.petrinet.Place;
import pl.edu.mimuw.irs.rcp.view.figure.FigureWrapper;
import pl.edu.mimuw.irs.rcp.view.figure.TGPlaceShape;



/**
 * @author Jakub Rauch
 * Created on: 2009-05-28
 */
public class TGPlaceEditPart extends PlaceEditPart implements TokenGameEditPart {

	// *** Attributes

	// *** Methods
	
	protected void refreshVisuals() {
		
		FigureWrapper wrapper = (FigureWrapper)getFigure();
		TGPlaceShape placeShape = (TGPlaceShape)wrapper.getFigure();
		Place node = (Place)getModel();
		placeShape.setTokens(node.getTokens());
		
		Label label;
		wrapper.setLineWidth(1);
		label = new Label(node.getId());
		Font placeFont = new Font(null, "Arial", 8, SWT.NORMAL);

		label.setFont(placeFont);
		label.setTextAlignment(PositionConstants.CENTER);
        label.setTextPlacement(PositionConstants.SOUTH);
		label.setBounds(wrapper.getBounds().crop(IFigure.NO_INSETS));
		wrapper.setLabel(label);
		
		placeShape.setTokens(node.getTokens());
	}
	
	protected NodeShape getNodeShape() {
		return NodeShape.TGPLACE;
	}
}
